* set working directory 

cd "/Users/justinrobinson/Library/CloudStorage/OneDrive-Personal/Postgraduate/PhD/Submissions/Patrimony paper/BJPS"

* NOTE - all of the various .dta files provided on the BJPS dataverse will need to be downloaded to the working directory folder that in order to run the analysis. 

**# 1. Parental data coding 

** begin by identifying parental voting preferences for each respondent's first parent and adding them to the model data. 

* Load up the xhhrel data containing parental ids: 

use xhhrel.dta, clear


* Keep all those that have a first parent in the sample:

drop if bpx_pidp_1==-8

keep pidp bpx_pidp_1 osm_hh

* pidp uniquely identifies the individual (i.e. the offspring), bpx_pidp_1 identifies the second parent. 

save "temp_parent1", replace

use "temp_parent1", clear

* The next step is to combine the parental identifiers with info from the main dataset on parental voting preferences. 
* Load up the political info file:

use all_waves_wide.dta, clear

* change the name of the identifier to match the first parent identifier (needed for merge): 
rename pidp bpx_pidp_1

* save this .dta file 

save "m_parent1", replace

* Then open up the first parental data set

use "temp_parent1", clear

* and merge with the m_parent1 data set

merge m:1 bpx_pidp_1 using "m_parent1", keep(match)

drop _merge

browse

* Renaming vote choice and gender to indicate that it corresponds to the first parent:

rename *ConPW* P1_=
rename *LabPW* P1_=
rename *sexW* P1_sex=

* Retaining only the necessary variables 

keep pidp P1_voteCon* P1_voteLab* P1_sex* osm_hh

browse

* merge with the the data set, in wide format

merge 1:1 pidp using all_waves_wide.dta

drop _merge

* Now save as a new file. This is the model data, in wide format, with parental voting preferences included for each individual's first parent. 

save "all_waves_wide_P1", replace

** Now repeat the process to identify parental voting preferences for each respondent's second parent and add them to the model data. 

*first load up xhhrel file: 

use xhhrel.dta, clear

*Keep only those that have a second parent in the sample: 

drop if bpx_pidp_2==-8

keep pidp bpx_pidp_2 osm_hh

browse

* again pidp uniquely identifies the individual (i.e. the offspring) and bpx_pidp_2 identifies the parent (this time the second parent):

save "temp_parent2", replace

use "temp_parent2", clear 

*Load up the political info file:

use all_waves_wide.dta, clear

* change the name of the identifier to match the second parent identifier (needed for merge): 

rename pidp bpx_pidp_2

save "m_parent2", replace

* Now merge with family ID file:

use "temp_parent2", clear

merge m:1 bpx_pidp_2 using "m_parent2", keep(match)

browse

* Renaming vote choice and gender to indicate that it corresponds to the second parent:

rename *ConPW* P2_=
rename *LabPW* P2_=
rename *sexW* P2_sex=

keep pidp P2_voteCon* P2_voteLab* P2_sex* osm_hh

browse

* Now merge this file with the model data containing respondent parental preferences for the first parent. 

merge 1:1 pidp using "all_waves_wide_P1"

browse

* then save this .dta file. This data set contains the all the respondent info used in the main analysis, plus info on parental voting preferences for those who have parents in the data set too. 

save "all_waves_wide_P2", replace

* Now the data needs to be reshaped. First retain only the necessary studys vars.

keep osm_hh pidp hidpW* sexW* ageW* ethnicW* educW* countryW* regionW* mortgageW* occupation_statusW* voteConAW* voteLabAW* turnoutAW* voteConPW* voteLabPW* BUvalW* SIVvalW* HHvalW* patvalW* patval_incW* incomeW* pat_SHW* pat_BUW* pat_SAVW* pat_HOW* pat_INVW* patcount_4W* patcount_5W* patval_diffW* P1_voteConPW* P2_voteConPW* P1_voteLabPW* P2_voteLabPW* P1_sexsexW* P2_sexsexW* maritalW* childrenW* unemployedW* retiredW*

* and then reshape long: 

reshape long hidpW sexW ageW ethnicW educW countryW regionW mortgageW occupation_statusW voteConAW voteLabAW turnoutAW voteConPW voteLabPW BUvalW SIVvalW HHvalW patvalW patval_incW incomeW pat_SHW pat_BUW pat_SAVW pat_HOW pat_INVW patcount_4W patcount_5W  patval_diffW P1_voteConPW P2_voteConPW P1_voteLabPW P2_voteLabPW P1_sexsexW P2_sexsexW maritalW childrenW unemployedW retiredW, i(pidp) j(wave)

browse

xtset pidp wave
drop if hidpW==.

	sort pidp wave
	
	bysort pidp: gen obs = _n
	
	bysort pidp: egen totobs = count(obs)
	
	tab totobs

	xtdes

** now some data cleaning and prep is required before the models can be estimated. 
	
* Adding labels for wave, occupation and region: 

tab occupation_statusW
label variable occupation_statusW ""
label define occupation_statusWlabel 1 "Management and professional" 2 "Intermediate" 3 "Routine" 4 "Unemployed"
label values occupation_statusW occupation_statusWlabel 
tab occupation_statusW

tab wave
label define wavelabel 1 "Wave 1" 2 "Wave 2" 3 "Wave 3" 4 "Wave 4" 5 "Wave 5" 6 "Wave 6" 7 "Wave 7" 8 "Wave 8" 9 "Wave 9" 10 "Wave 10" 11 "Wave 11" 12 "Wave 12"
label values wave wavelabel
tab wave

tab regionW
recode regionW -9=.

*Drop those obs with missing data for personal vote preferences: 

drop if voteConPW==.

tab voteConPW


* Recode parental voting preferences by gender.

numlabel, add
tab P1_sexsexW

gen mother_voteConW=.
replace mother_voteConW = 0 if (((P1_voteConPW==0) & (P1_sexsexW==2))|(((P2_voteConPW==0) & (P2_sexsexW==2))))
replace mother_voteConW = 1 if (((P1_voteConPW==1) & (P1_sexsexW==2))|(((P2_voteConPW==1) & (P2_sexsexW==2))))

gen father_voteConW=.
replace father_voteConW = 0 if (((P1_voteConPW==0) & (P1_sexsexW==1))|(((P2_voteConPW==0) & (P2_sexsexW==1))))
replace father_voteConW = 1 if (((P1_voteConPW==1) & (P1_sexsexW==1))|(((P2_voteConPW==1) & (P2_sexsexW==1))))

tab father_voteConW
tab mother_voteConW 

* dropping missing obs for country and education variables 

tab countryW
recode countryW -9=.
tab educ
recode educW -8=.

* Coding transformed versions of the patrimony (value) variable, so that a one-unit increase equates to (a) an increase of one standard deviation and (b) an increase of 0.5 standard deviations:

summ patvalW, detail
gen patvalW_SD=patvalW/592940
gen patvalW_halfSD=patvalW/296470

summ patvalW_SD, detail

* coding transformed version of the income variable, so that a one-unit increase equates to an increase of one standard deviation

summ incomeW
gen incomeW_SD=incomeW/5485

* now restrict the sample to all those individuals for whom we accompanying information on parental voting preferences for both parents:


drop if father_voteConW==.
drop if mother_voteConW==.

* now drop all those with missing data on the value patrimony measure: 

drop if patvalW_SD==.

xtdes

*N = 3946, 7027 obs, 915 outcomes that = 1 for Con voting. 

* Now the data can be saved for analysis: 

save long_both_parents.dta, replace

**# 2. Markov model preparation

** We begin by coding a .dta file that does not include change scores for the markov models. due to the lack of change scores, this model includes four waves of data. 

* begin by loading up the data in wide format:

use all_waves_wide.dta, clear

* due to the nature of the LMest package, all those individuals with missing obs for any covariates must be dropped from the sample. THis is limited to the four waves of data at which both the count and value measures of patrimony are measured (waves 2, 4, 6 and 10)

keep if patcount_4W2!=. & patcount_4W4!=. & patcount_4W6!=. & patcount_4W10!=. & patvalW2!=. & patvalW4!=. & patvalW6!=. & patvalW10!=. & ageW2!=. & ageW4!=. & ageW6!=. & ageW10!=. & educW2!=. & educW4!=. & educW6!=. & educW10!=. & sexW2!=. & sexW4!=. & sexW6!=. & sexW10!=. & ethnicW2!=. & ethnicW4!=. & ethnicW6!=. & ethnicW10!=. & occupation_statusW2!=. & occupation_statusW4!=. & occupation_statusW6!=. & occupation_statusW10!=. & mortgageW2!=. & mortgageW4!=. & mortgageW6!=. & mortgageW10!=. & regionW2!=. & regionW4!=. & regionW6!=. & regionW10!=. & incomeW2!=. & incomeW4!=. & incomeW6!=. & incomeW10!=. & unemployedW2!=. & unemployedW4!=. & unemployedW6!=. & unemployedW10!=. & retiredW2!=. & retiredW4!=. & retiredW4!=. & retiredW6!=. & retiredW10!=. & childrenW2!=. & childrenW4!=. & childrenW6!=. & childrenW10!=. & maritalW2!=. & maritalW4!=. & maritalW6!=. & maritalW10!=. 

* the next step is to drop all non-model variables

keep pidp voteConPW2 voteConPW4 voteConPW6 voteConPW10 patcount_4W2 patcount_4W6 patcount_4W4 patcount_4W10 patvalW2 patvalW4 patvalW6 patvalW10 ageW2 ageW4 ageW6 ageW10 educW2 educW4 educW6 educW10 sexW2 sexW4 sexW6 sexW10 ethnicW2 ethnicW4 ethnicW6 ethnicW10 occupation_statusW2 occupation_statusW4 occupation_statusW6 occupation_statusW10 mortgageW2 mortgageW4 mortgageW6 mortgageW10 regionW2 regionW4 regionW6 regionW10 incomeW2 incomeW4 incomeW6 incomeW10 unemployedW2 unemployedW4 unemployedW6 unemployedW10 retiredW2 retiredW4 retiredW6 retiredW10 childrenW2 childrenW4 childrenW6 childrenW10 maritalW2 maritalW4 maritalW6 maritalW10

* LMest requires variables to be labelled so that each measurement occasion is a +1 increase from the previous (i.e. n, n+1, n+2, n+3). The variables thus need to relabelled as they currently increase in intervals of 2. 

rename (voteConPW2 voteConPW4 voteConPW6 voteConPW10) (voteConPW1 voteConPW2 voteConPW3 voteConPW4)
rename (patcount_4W2 patcount_4W4 patcount_4W6 patcount_4W10) (patcount_4W1 patcount_4W2 patcount_4W3 patcount_4W4)
rename (patvalW2 patvalW4 patvalW6 patvalW10) (patvalW1 patvalW2 patvalW3 patvalW4)
rename (ageW2 ageW4 ageW6 ageW10) (ageW1 ageW2 ageW3 ageW4)
rename (educW2 educW4 educW6 educW10) (educW1 educW2 educW3 educW4)
rename (sexW2 sexW4 sexW6 sexW10) (sexW1 sexW2 sexW3 sexW4)
rename (ethnicW2 ethnicW4 ethnicW6 ethnicW10) (ethnicW1 ethnicW2 ethnicW3 ethnicW4)
rename (occupation_statusW2 occupation_statusW4 occupation_statusW6 occupation_statusW10) (occupation_statusW1 occupation_statusW2 occupation_statusW3 occupation_statusW4)
rename (mortgageW2 mortgageW4 mortgageW6 mortgageW10) (mortgageW1 mortgageW2 mortgageW3 mortgageW4)
rename (regionW2 regionW4 regionW6 regionW10) (regionW1 regionW2 regionW3 regionW4)
rename (incomeW2 incomeW4 incomeW6 incomeW10) (incomeW1 incomeW2 incomeW3 incomeW4)
rename (unemployedW2 unemployedW4 unemployedW6 unemployedW10) (unemployedW1 unemployedW2 unemployedW3 unemployedW4)
rename (retiredW2 retiredW4 retiredW6 retiredW10) (retiredW1 retiredW2 retiredW3 retiredW4)
rename (childrenW2 childrenW4 childrenW6 childrenW10) (childrenW1 childrenW2 childrenW3 childrenW4)
rename (maritalW2 maritalW4 maritalW6 maritalW10) (maritalW1 maritalW2 maritalW3 maritalW4)

* The data can then be converted into long format: 

reshape long voteConPW patcount_4W patvalW ageW educW sexW ethnicW occupation_statusW mortgageW regionW incomeW unemployedW retiredW childrenW maritalW, i(pidp) j(wave)

* check for missing values among the covariates, and make sure that each dummy variable is coded appropriately (i.e. 0 or 1)

tab educW
recode educW (-8=.)

recode sexW (1=0) (2=1) (-9=.), gen(genderW)

tab ethnicW

tab occupation_statusW

tab mortgageW

recode regionW (-9=.)

tab regionW
drop if regionW==.

tab unemployedW 
tab retiredW 
tab childrenW 
tab maritalW


drop if educW==.
drop if genderW==.

drop if patcount_4W==.
drop if patvalW==.

* for the four wave models, we retain only those individuals with complete information across all four waves. First step here is to code a total observations indicator

	bysort pidp: gen obs = _n
	
	bysort pidp: egen totobs = count(obs) 
	
* and then keep only those individuals who provide non-missing information at all four waves:


tab totobs
keep if totobs==4

* dropping labels

label drop _all

* then code transformed version of the patrimony value measure and income variable:

gen patvalW_halfSD=patvalW/221918.1
gen incomeW_SD=incomeW/6005.069

summ patvalW_halfSD
summ incomeW_SD

save markov_data_4waves.dta, replace

** We next create a data set that includes change scores. Consequently this model only contains three waves of data (as the first wave is needed to provide a baseline value for the change scores)

* begin by loading up the data in wide format:

use all_waves_wide.dta, clear

* Again, the first step is to drop all those with missing information for any of the model variables:

keep if patcount_4W2!=. & patcount_4W4!=. & patcount_4W6!=. & patcount_4W10!=. & patvalW2!=. & patvalW4!=. & patvalW6!=. & patvalW10!=. & ageW4!=. & ageW6!=. & ageW10!=. & educW4!=. & educW6!=. & educW10!=. & sexW4!=. & sexW6!=. & sexW10!=. & ethnicW6!=. & ethnicW10!=. & occupation_statusW4!=. & occupation_statusW6!=. & occupation_statusW10!=. & mortgageW4!=. & mortgageW6!=. & mortgageW10!=. & regionW4!=. & regionW6!=. & regionW10!=. & incomeW4!=. & incomeW6!=. & incomeW10!=. & unemployedW4!=. & unemployedW6!=. & unemployedW10!=. & retiredW4!=. & retiredW6!=. & retiredW10!=. & childrenW4!=. & childrenW6!=. & childrenW10!=. & maritalW4!=. & maritalW6!=. & maritalW10!=. 

keep pidp voteConPW4 voteConPW6 voteConPW10 patcount_4W2 patcount_4W6 patcount_4W4 patcount_4W10 patvalW2 patvalW4 patvalW6 patvalW10 ageW4 ageW6 ageW10 educW4 educW6 educW10 sexW4 sexW6 sexW10 ethnicW4 ethnicW6 ethnicW10 occupation_statusW4 occupation_statusW6 occupation_statusW10 mortgageW4 mortgageW6 mortgageW10 regionW4 regionW6 regionW10 incomeW4 incomeW6 incomeW10 unemployedW4 unemployedW6 unemployedW10 retiredW4 retiredW6 retiredW10 childrenW4 childrenW6 childrenW10 maritalW4 maritalW6 maritalW10

* Next, we code change scores for count patrimony:

gen patcount_incW4=0 if patcount_4W4<patcount_4W2|patcount_4W4==patcount_4W2
replace patcount_incW4=1 if patcount_4W4>patcount_4W2

gen patcount_incW6=0 if patcount_4W6<patcount_4W4|patcount_4W6==patcount_4W4
replace patcount_incW6=1 if patcount_4W6>patcount_4W4

gen patcount_incW10=0 if patcount_4W10<patcount_4W6|patcount_4W10==patcount_4W6
replace patcount_incW10=1 if patcount_4W10>patcount_4W6

gen patcount_lossW4=0 if patcount_4W4>patcount_4W2|patcount_4W4==patcount_4W2
replace patcount_lossW4=1 if patcount_4W4<patcount_4W2

gen patcount_lossW6=0 if patcount_4W6>patcount_4W4|patcount_4W6==patcount_4W4
replace patcount_lossW6=1 if patcount_4W6<patcount_4W4

gen patcount_lossW10=0 if patcount_4W10>patcount_4W6|patcount_4W10==patcount_4W6
replace patcount_lossW10=1 if patcount_4W10<patcount_4W6

* then code change scores for the value measure of patrimony: 

gen patval_diffW4 = (patvalW4-patvalW2)
summ patval_diffW4

gen patval_diffW6 = (patvalW6-patvalW4)
summ patval_diffW6

gen patval_diffW10 = patvalW10-patvalW6
summ patval_diffW10

* the wave 2 patrimony measures can now be dropped:

drop patcount_4W2 patvalW2

* again, the variables need to be renamed (this time from W1 to W3) before fitting the model using the LMest package:

*Renaming to waves 1-3 for LMest:
rename (voteConPW4 voteConPW6 voteConPW10) (voteConPW1 voteConPW2 voteConPW3)
rename (patcount_4W4 patcount_4W6 patcount_4W10) (patcount_4W1 patcount_4W2 patcount_4W3)
rename (patcount_incW4 patcount_incW6 patcount_incW10) (patcount_incW1 patcount_incW2 patcount_incW3)
rename (patcount_lossW4 patcount_lossW6 patcount_lossW10) (patcount_lossW1 patcount_lossW2 patcount_lossW3)
rename (patvalW4 patvalW6 patvalW10) (patvalW1 patvalW2 patvalW3)
rename (patval_diffW4 patval_diffW6 patval_diffW10) (patval_diffW1 patval_diffW2 patval_diffW3)
rename (ageW4 ageW6 ageW10) (ageW1 ageW2 ageW3)
rename (educW4 educW6 educW10) (educW1 educW2 educW3)
rename (sexW4 sexW6 sexW10) (sexW1 sexW2 sexW3)
rename (ethnicW4 ethnicW6 ethnicW10) (ethnicW1 ethnicW2 ethnicW3)
rename (occupation_statusW4 occupation_statusW6 occupation_statusW10) (occupation_statusW1 occupation_statusW2 occupation_statusW3)
rename (mortgageW4 mortgageW6 mortgageW10) (mortgageW1 mortgageW2 mortgageW3)
rename (regionW4 regionW6 regionW10) (regionW1 regionW2 regionW3)
rename (incomeW4 incomeW6 incomeW10) (incomeW1 incomeW2 incomeW3)
rename (unemployedW4 unemployedW6 unemployedW10) (unemployedW1 unemployedW2 unemployedW3)
rename (retiredW4 retiredW6 retiredW10) (retiredW1 retiredW2 retiredW3)
rename (childrenW4 childrenW6 childrenW10) (childrenW1 childrenW2 childrenW3)
rename (maritalW4 maritalW6 maritalW10) (maritalW1 maritalW2 maritalW3)

* the data can then be converted into long format: 

reshape long voteConPW patcount_4W patcount_incW patcount_lossW patvalW patval_diffW ageW educW sexW ethnicW occupation_statusW mortgageW regionW incomeW unemployedW retiredW childrenW maritalW, i(pidp) j(wave)

* check for missing values among the covariates, and make sure that each dummy variable is coded appropriately (i.e. 0 or 1)

tab educW
recode educW (-8=.)

recode sexW (1=0) (2=1) (-9=.), gen(genderW)

tab ethnicW

tab occupation_statusW

tab mortgageW

recode regionW (-9=.)

tab regionW
drop if regionW==.

drop if educW==.
drop if genderW==.

drop if patcount_4W==.
drop if patvalW==.

* for the three wave models, we retain only those individuals with complete information across three waves. First step here is to code a total observations indicator:

	bysort pidp: gen obs = _n
	
	bysort pidp: egen totobs = count(obs) 

* and then keep only those individuals who provide non-missing information at all four waves:

tab totobs
keep if totobs==3

* drop variable labels:

label drop _all

* code transformed patrimony and income measures: 

summ patvalW
summ incomeW

gen patvalW_halfSD=patvalW/207377
gen incomeW_SD=incomeW/6736.716
gen patval_diffWSD=patval_diffW/207377

summ patvalW_halfSD
summ incomeW_SD

save markov_data_3waves.dta, replace

**# 3. Main analysis - descriptive statistics 

* begin by loading in the dataset in long format:

use all_waves_long.dta, clear

** descriptive stats for the main sample: 

xtdes

drop if voteConPW==.
drop if patcount_4W==.

tab voteConPW
summ patcount_4W
tab pat_HOW
tab pat_BUW
tab pat_SAVW
tab pat_SHW
summ patvalW
summ HHvalW
summ BUvalW
summ SIVvalW  
summ incomeW
tab genderW
summ age
tab ethnicW
tab educW
tab occupation_statusW
tab childrenW
tab maritalW 
tab retiredW
tab unemployedW
tab mortgageW
tab countryW

* calculating the amout of within-person variation in patrimony:

bysort pidp: gen pat_ch=1 if patcount_4W[_n]>patcount_4W[_n-1]&(patcount_4W[_n]!=.&patcount_4W[_n-1]!=.)
bysort pidp: replace pat_ch=0 if patcount_4W[_n]==patcount_4W[_n-1]&(patcount_4W[_n]!=.&patcount_4W[_n-1]!=.)
bysort pidp: replace pat_ch=-1 if patcount_4W[_n]<patcount_4W[_n-1]&(patcount_4W[_n]!=.&patcount_4W[_n-1]!=.)

tab pat_ch

* calculating within-person variation in the value measure: 

use all_waves_long.dta, clear

drop if voteConPW==.

bysort pidp: gen patval_ch=patvalW[_n]-patvalW[_n-1] if (patvalW[_n]!=0&patvalW[_n-1]!=0)
bysort pidp: replace patval_ch=patvalW[_n]-patvalW[_n-2] if patvalW[_n-1]==. & (patvalW[_n]!=0&patvalW[_n-2]!=0)
bysort pidp: replace patval_ch=patvalW[_n]-patvalW[_n-3] if patvalW[_n-1]==.&patvalW[_n-2]==. & (patvalW[_n]!=0&patvalW[_n-3]!=0)
summ patval_ch, detail

bysort pidp: gen patval_ch_cat=-2 if patval_ch<=-100000
bysort pidp: replace patval_ch_cat=-1 if patval_ch<-50000&patval_ch>-100000
replace patval_ch_cat=0 if patval_ch>=-50000&patval_ch<=50000
replace patval_ch_cat=1 if patval_ch>=50000&patval_ch<=100000
bysort pidp: replace patval_ch_cat=2 if patval_ch>100000


** descriptive stats for the first-time homeowner sample:

use first_time_owners.dta, clear 

drop if voteConPW==.
drop if pat_HOW==.

tab voteConPW
tab pat_HOW
summ incomeW
tab genderW
summ age
tab ethnicW
tab educW
tab occupation_statusW
tab childrenW
tab maritalW 
tab retiredW
tab unemployedW
tab mortgageW
tab regionW

**# 4. Main analysis - cross-sectional models 

* load in the data in long format:

use all_waves_long.dta, clear

* first we fit a pooled ols model 

logit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW, vce(cluster pidp)
est store pooledOLS

* And then calculate odds ratios

logit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW, or vce(cluster pidp)

* estimating models at each wave 
* wave 2: 

logit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW if wave == 2, vce(cluster pidp)

logit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW if wave == 2, or vce(cluster pidp)

* wave 4: 

logit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW if wave == 4, vce(cluster pidp)

logit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW if wave == 4, or vce(cluster pidp)

* wave 6:

logit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW if wave == 6, vce(cluster pidp)

logit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW if wave == 6, or vce(cluster pidp)

* wave 10:

logit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW if wave == 10, vce(cluster pidp)

logit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW if wave == 10, or vce(cluster pidp)

**# 5. Main analysis - random and two-way fixed effects models:

*Random effects: 
xtlogit voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW i.wave, vce(cluster pidp)
est store RE_Con

xtlogit voteConPW patcount_4W patvalW_halfSD i.wave incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW, or vce(cluster pidp)

* two-way fixed effects - no covariates:
xtlogit voteConPW patcount_4W patvalW_halfSD i.wave, fe
est store FE_nocontrols_Con

xtlogit voteConPW patcount_4W patvalW_halfSD i.wave, or fe

* two-way fixed effects - with covariates: 

xtlogit voteConPW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW i.wave, fe
est store FE_controls_Con

xtlogit voteConPW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW i.wave, or fe

*Plot:  

graph set window fontface "Times New Roman"


coefplot (RE_Con, label(Time FE) msym(O) offset(.2) col(gs1) ciopts(lcolor(gs1))) (FE_nocontrols_Con, label(Time + Individual FE, no controls) msym(S) offset (0) col(gs6) ciopts(lcolor(gs6))) (FE_controls_Con, label(Time + Individual FE, controls) msym(D) offset(-.2) col(gs12) ciopts(lcolor(gs12))), ///
 keep (patcount_4W || patvalW_halfSD) /// 
 xline(0) ///
 coeflabels(patcount_4W = "Patrimony (count)" patvalW_halfSD = "Patrimony (value)" ) ///
 legend(pos(6) fcolor(white) rows(1) size(*0.8) region(lstyle(none))) ///
title("") note("Note: figure 1 presents logit coefficients and robust standard errors for three models: Conservative voting regressed" "on patrimony using wave fixed effects, two-way fixed effects (no controls) and two-way fixed effects (w/ controls).") 

**# 6. Main analysis - placebo tests: 

** Egotropic financial well-being: 

* load in the data in long format:

use all_waves_long.dta, clear

* retain only those waves at which the patrimony variables are present:

drop if (wave==1)|(wave==3)|(wave==5)|(wave==7)|(wave==8)|(wave==9)|(wave==11)|(wave==12)

* fit the baseline model and calculate ORs

xtlogit voteConPW fsitu_egoW i.wave, fe
xtlogit voteConPW fsitu_egoW i.wave, fe or

* fit the covariate model and calculate ORs

xtlogit voteConPW fsitu_egoW incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteConPW fsitu_egoW incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe or

** Turnout 

* fit the baseline model and calculate ORs

xtlogit turnoutP_dknW patcount_4W patvalW_halfSD i.wave, fe
xtlogit turnoutP_dknW patcount_4W patvalW_halfSD i.wave, or fe

* fit the covariate model and calculate ORs

xtlogit turnoutP_dknW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit turnoutP_dknW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

**# 7. Main analysis - robustnesss checks (alternative model specifications):

// Assets included as individual items

* load in the data in long format:

use all_waves_long.dta, clear

* Begin by calculating transformed versions of the individual value items: 

summ BUvalW
gen BUvalW_SD = BUvalW/604.2557

summ SIVvalW 
gen SIVvalW_SD = SIVvalW/3665.209

summ HHvalW
gen HHvalW_SD = HHvalW/614596.1  

*Model I - wave FE: 
xtlogit voteConPW pat_BUW pat_SHW pat_SAVW pat_HOW BUvalW_SD SIVvalW_SD HHvalW_SD genderW incomeW_SD ageW i.ethnicW i.educW ib8.regionW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave
est store highrisk_model_I
est replay highrisk_model_I
est replay highrisk_model_I, or


*Model II - two-way FE, baseline model: 
xtlogit voteConPW pat_BUW pat_SHW pat_SAVW pat_HOW BUvalW_SD SIVvalW_SD HHvalW_SD i.wave, fe
est store highrisk_model_II
est replay highrisk_model_II, or 

*Model III - two-way FE, covariate model: 

xtlogit voteConPW pat_BUW pat_SHW pat_SAVW pat_HOW BUvalW_SD SIVvalW_SD HHvalW_SD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
est store highrisk_model_III
est replay highrisk_model_III, or 


// Separate asset types in an individual models

*Homeownership:
xtlogit voteConPW pat_HOW pat_SHW HHvalW_SD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
est store homeownership_alone
est replay homeownership_alone
est replay homeownership_alone, or

*Business
xtlogit voteConPW pat_BUW BUvalW_SD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
est store business_alone
est replay business_alone, or

*Savings/investments
xtlogit voteConPW pat_SAVW SIVvalW_SD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
est store siv_alone
est replay siv_alone, or


// Actual vote choice as the outcome variable

* load in the data in long format

use all_waves_long.dta, clear

* wave FE model and accompanying ORs

xtlogit voteConAW patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW i.wave, vce(cluster pidp)

xtlogit voteConAW patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW i.wave, or vce(cluster pidp)

* two-way FE, baseline model: 

xtlogit voteConAW patvalW_halfSD i.wave, fe

xtlogit voteConAW patvalW_halfSD i.wave, or fe

* two-way FE, with covariates: 

xtlogit voteConAW patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe

xtlogit voteConAW patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

// Lagged patrimony effects

* load in the data in long-format:

use all_waves_long.dta, clear

* single lags of count and value - baseline model:

xtlogit voteConPW patcount_4W patvalW_halfSD l2.patcount_4W l2.patvalW_halfSD i.wave, fe

xtlogit voteConPW patcount_4W patvalW_halfSD l2.patcount_4W l2.patvalW_halfSD i.wave, or fe

 * single lags - covariate model: 

xtlogit voteConPW patcount_4W patvalW_halfSD l2.patcount_4W l2.patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe

xtlogit voteConPW patcount_4W patvalW_halfSD l2.patcount_4W l2.patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

* now we fit models that only include the value measure, to allow for multiple lags
* we begin with a baseline model without lags (model I):

xtlogit voteConPW patvalW_halfSD i.wave, fe
xtlogit voteConPW patvalW_halfSD i.wave, or fe

* covariate model without lags (model II):
xtlogit voteConPW patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteConPW patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

* baseline model with a single lag (model III): 
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD i.wave, fe
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD i.wave, or fe

* covariate model with a single lag (model IV): 
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

* baseline model with two lags (model V):
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD l2.patvalW_halfSD i.wave, fe
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD l2.patvalW_halfSD i.wave, or fe 

* covariate model with two lags (model VI): 
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD l2.patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD l2.patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

* baseline model with 3 lags (model VII): 
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD l2.patvalW_halfSD l3.patvalW_halfSD i.wave, fe
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD l2.patvalW_halfSD l3.patvalW_halfSD i.wave, or fe

* covariate model with 3 lags (model VIII): 
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD l2.patvalW_halfSD l3.patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteConPW patvalW_halfSD l.patvalW_halfSD l2.patvalW_halfSD l3.patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

// PID as the outcome variable: 

* load in the data in long-format:

use all_waves_long.dta, clear

* the outcome variable in these models is a dummy for Conservative party identification

* we first fit models that include both the count and value measures 
* baseline model (model I), with accompanying ORs

xtlogit pid_ConW patcount_4W patvalW_halfSD i.wave, fe
xtlogit pid_ConW patcount_4W patvalW_halfSD i.wave, or fe

* covariate model (model II), with accompanying ORs

xtlogit pid_ConW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit pid_ConW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

* then we fit models that only include the value measured
* baseline model (model III), with accompanying ORs

xtlogit pid_ConW patvalW_halfSD i.wave, fe
xtlogit pid_ConW patvalW_halfSD i.wave, or fe

* covariate model (model IV), with accompanying ORs

xtlogit pid_ConW patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit pid_ConW patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

// Undecided voters

* load in the data in long-format:

use all_waves_long.dta, clear

tab voteCon_2PW
recode voteCon_2PW 2=.

* wave FE model, with accompanying ORs (model I)

xtlogit voteCon_2PW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW i.wave, vce(cluster pidp)
xtlogit voteCon_2PW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW i.wave, or vce(cluster pidp)

* two-way FE baseline model, with accompanying ORs (model II)

xtlogit voteCon_2PW patcount_4W patvalW_halfSD i.wave, fe
xtlogit voteCon_2PW patcount_4W patvalW_halfSD i.wave, or fe

* two-way FE covariate model with accompanying ORs (model III)

xtlogit voteCon_2PW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteCon_2PW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

// Multinomial models 

* load in the data in long-format:

use all_waves_long.dta, clear

* fitting and storing the baseline model 

xtmlogit vote_mPW patvalW_halfSD i.wave, fe b(2)
est store mlogit_b

* fitting and storing the covariate model 

xtmlogit vote_mPW patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe b(2)
est store mlogit_c

est dir

* estimating relative risk ratios for each model:

est replay mlogit_b, rrr
est replay mlogit_c, rrr


**# 8. Main analysis - robustnesss checks (alternative estimators):

// Non-linear patrimony

* load in the data in long-format:

use all_waves_long.dta, clear

* coding a log-transformed value measure:

gen logPV_halfSD = log(patvalW_halfSD)
summ logPV_halfSD

* fit and store the wave FE model 

xtlogit voteConPW i.patcount_4W logPV_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW i.wave, vce(cluster pidp)
est store nonlinear_RE

* replay the model with odds ratios: 

est replay nonlinear_RE, or

* fit and store the two-way FE basline model

xtlogit voteConPW i.patcount_4W logPV_halfSD i.wave, fe
est store nonlinear_FE1

* replay the model with odds ratios: 

est replay nonlinear_FE1, or

* fit and store the two-way FE covariate model:

xtlogit voteConPW i.patcount_4W logPV_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
est store nonlinear_FE2

* replay the model with odds ratios: 

est replay nonlinear_FE2, or 

// Incidental parameter problem

* load in the data in long-format:

use all_waves_long.dta, clear


* installing the logitfe command

ssc install logitfe

* Model I - baseline model, no bias correction;

logitfe voteConPW patcount_4W patvalW_halfSD, noc ieffects(yes) teffects(yes)


* Model II - baseline model, with analytical bias correction:

logitfe voteConPW patcount_4W patvalW_halfSD, an ieffects(yes) teffects(yes)

* Model III - covariate model, no bias correction:

logitfe voteConPW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW , noc ieffects(yes) teffects(yes)

* model IV - covariate model, with analytical bias correction: 

logitfe voteConPW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW , an ieffects(yes) teffects(yes)

// LPM 

* load in the data in long-format:

use all_waves_long.dta, clear

* to retain only those individuals who appear at multiple waves, we first drop the existing observation and total observation variables 

drop obs totobs

* and then code new observation and total observation variables 

	sort pidp wave
	
	bysort pidp: gen obs = _n
	
	bysort pidp: egen totobs = count(obs)
	
	tab totobs
	
* then drop those individuals who only appear once in the data
	
	drop if totobs==1
	
* to drop all those individuals with unchanging responses on the outcome var, we first calculate variables that represent the individually-specific maximum and minimum value for each respondent 
	
bysort pidp: egen maxCon=max(voteConPW)
bysort pidp: egen minCon=min(voteConPW)

* then drop all those with a max value of 0 or a min value of 1 (who give 0 values or 1 values at all waves)

drop if maxCon==0
drop if minCon==1
	
	xtdes
	
	
* wave FE model:

xtreg voteConPW patcount_4W patvalW_halfSD incomeW_SD genderW ageW i.ethnicW i.educW i.occupation_statusW mortgageW ib8.regionW childrenW maritalW retiredW unemployedW i.wave, vce(cluster pidp)

*Fixed effects - no controls:

xtreg voteConPW patcount_4W patvalW_halfSD i.wave, fe

*Fixed effects - controls:

xtreg voteConPW patcount_4W patvalW_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe


**# 9. First-time homeowner analysis: 

* load in the first-time homeowner data set:

use first_time_owners.dta, clear

* baseline model

xtlogit voteConPW pat_HOW i.wave, fe
xtlogit voteConPW pat_HOW i.wave, or fe


* covariate model (model II)

xtlogit voteConPW pat_HOW incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteConPW pat_HOW incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe


* Now we conduct a placebo test, using egotropic financial wellbeing as the explanatory variable
* first fit a baseline model:

xtlogit voteConPW fsitu_egoW i.wave, fe
xtlogit voteConPW fsitu_egoW i.wave, or fe


* then fit a covariate model:

xtlogit voteConPW fsitu_egoW incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteConPW fsitu_egoW incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe


**# 10. Lead effects

// With the main data 

* load in the data in long-format:

use all_waves_long.dta, clear

* baseline model with a t+1 lead (model I):
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD i.wave, fe
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD i.wave, or fe

* covariate model with a t+1 lead (model II)
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave i.wave, or fe

* baseline model with t+1 and t+2 leads (model III)

xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD PV_2lead_halfSD i.wave, fe
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD PV_2lead_halfSD i.wave, or fe

* covariate model with t+1 and t+2 leads (model IV)
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD PV_2lead_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD PV_2lead_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe

* baseline model with t+1, t+2 and t+3 leads (model V)
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD PV_2lead_halfSD PV_3lead_halfSD i.wave, fe
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD PV_2lead_halfSD PV_3lead_halfSD i.wave, or fe

* covariate model with t+1, t+2 and t+3 leads (model VI)
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD PV_2lead_halfSD PV_3lead_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
xtlogit voteConPW patvalW_halfSD PV_1lead_halfSD PV_2lead_halfSD PV_3lead_halfSD incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, or fe


// With the first-time home owner data 

* load in the first-time homeowner data set:

use first_time_owners.dta, clear

* baseline model, including a t+1 lead (model I)

xtlogit voteConPW pat_HOW HO_1leadW i.wave, fe
xtlogit voteConPW pat_HOW HO_1leadW i.wave , or fe

* covariate model, including a t+1 lead (model II) 

xtlogit voteConPW pat_HOW HO_1leadW incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe
est store homeowner_modelIV
est replay homeowner_modelIV, or

* baseline model, including t+1 and t+2 leads (model III)

xtlogit voteConPW pat_HOW HO_1leadW HO_2leadW i.wave, fe
xtlogit voteConPW pat_HOW HO_1leadW HO_2leadW i.wave , or fe

* covariate model, including t+1 and t+2 leads (model IV)

xtlogit voteConPW pat_HOW HO_1leadW HO_2leadW incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe

est store homeowner_modelVI

est replay homeowner_modelVI, or

* baseline model, including t+1, t+2 and t+3 leads (model V)

xtlogit voteConPW pat_HOW HO_1leadW HO_2leadW HO_3leadW i.wave, fe

xtlogit voteConPW pat_HOW HO_1leadW HO_2leadW HO_3leadW i.wave , or fe

* covariate model model, including t+1, t+2 and t+3 leads (model VI)

xtlogit voteConPW pat_HOW HO_1leadW HO_2leadW HO_3leadW incomeW_SD ageW i.educW i.occupation_statusW mortgageW childrenW maritalW retiredW unemployedW i.wave, fe

est store homeowner_modelVIII

est replay homeowner_modelVIII, or

**# 11. British Election Study Panel analysis 

* load in the BESP data:

use BES_long.dta, clear 

* begin by fitting and storing the wave FE model 

xtlogit voteConW homeownerW i.econGenRetroW redistW ib17.hhincW gender ageW ethnicW higheducW ib3.p_socgradeW hh_childrenW marriedW retiredW unemployedW ib8.regionW ConPIDW ideologyW ib2.wave, vce (cluster id)

est store waveFE

* then calculate odds ratios
est replay waveFE, or

* fitting and storing the two-way FE baseline model: 
	
xtlogit voteConW i.econGenRetroW redistW homeownerW ib2.wave, fe 
est store TWFE_baseline

* calculating odds ratios 

est replay TWFE_baseline, or

* fitting and storing the two-way FE covariate model

xtlogit voteConW homeownerW i.econGenRetroW redistW ib17.hhincW ageW higheducW ib3.p_socgradeW hh_childrenW marriedW retiredW unemployedW ConPIDW ideologyW ib2.wave, fe 
est store TWFE_cov
est replay TWFE_cov, or

**# 12. British Household Panel study analysis 

* load in the BHPS data:

use BHPS_long.dta, clear

* fitting and storing the wave FE model: 

xtlogit bh_voteConPW bh_patcount_4W bh_patvalW_halfSD bh_incomeW_SD bh_genderW bh_ageW i.bh_educW i.bh_occupation_statusW bh_mortgageW ib8.bh_regionW bh_childrenW bh_marriedW bh_retiredW bh_unemployedW i.wave, vce(cluster pidp)

est store RE_BHPS

* calculating odds ratios 

est replay RE_BHPS, or

* fitting and storing the two-way FE baseline model: 

xtlogit bh_voteConPW bh_patcount_4W bh_patvalW_halfSD i.wave, fe
est store FE_b

* calculating odds ratios 

est replay FE_b, or

* fitting and storing the two-way FE covariate model:

xtlogit bh_voteConPW bh_patcount_4W bh_patvalW_halfSD bh_incomeW_SD bh_ageW i.bh_educW i.bh_occupation_statusW bh_mortgageW bh_childrenW bh_marriedW bh_retiredW bh_unemployedW i.wave, fe
est store FE_cov

* calculating odds ratios 

est replay FE_cov, or


